﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EntGuayasSLA.BL;
using EntGuayasSLA.BL.Archivos.Pdf;
using Ext.Net;
using EntGuayasSLA.BL.Licenciamiento;

namespace EGuayas.Web
{
    public partial class pgPruebas :pgBase
    {
        private X509Certificate2 ReadCertificado()
        {
            Persona objPersona = Persona.GetEditableRoot(Guid.Parse(GetSessionUsuario.PersonaId));
            string clave = Seguridad.DesEncriptar(objPersona.CertificadoClave);
            string fileName = MapPath(string.Format("~/{0}{1}{2}", ConfigurationManager.AppSettings.Get("PathCer"), GetSessionUsuario.PersonaId, ConfigurationManager.AppSettings.Get("ExtCer")));
            X509Certificate2 objCert = Certificate.GetX509Certificate2(clave, fileName);
            return objCert;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                var mail = Request.QueryString.Get("m");
                if (!string.IsNullOrEmpty(mail))
                {
                    MyMail.Enviar("", mail, "Prueba",
                              "Esto es una prueba <br> Atentamente,<br> Ing. Luis Cuenca", true,"Prueba ");
                }
                
                RegistrarLog(string.Format("{0}{1}{2}",MapPath(string.Format("~/{0}", ConfigurationManager.AppSettings.Get("PathCer"))),ConfigurationManager.AppSettings.Get("PwdCer"),Environment.NewLine));
                //Esto es una modificacion Ing. Diana Ortega
                X509Certificate2 objCert = ReadCertificado();
                //Certificate.GetX509Certificate2(ConfigurationManager.AppSettings.Get("PwdCer"), MapPath(string.Format("~/{0}", ConfigurationManager.AppSettings.Get("PathCer"))));
                var infoDetails = Certificate.ShowCertificateInfo(objCert, DateTime.Today);
                RegistrarLog(infoDetails);
            }
            catch (Exception ex)
            {
                RegistrarLog(ex);
            }
        }
    }
}